package io.tij;

import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Pattern;

public class DirList2 {
	public static  FilenameFilter getFileNameFilter(final String regex){
		return new FilenameFilter() {
			Pattern pattern = Pattern.compile(regex);
			
			public boolean accept(File dir, String name) {
				return pattern.matcher(name).matches();
			}
		};
	}
	
	public static void main(String[] args){
		
		File file = new File(".");
		String[] list = null;
		
		if(args.length == 0)
			list = file.list();
		else
			list = file.list(getFileNameFilter(args[0]));
		
		for(String item : list){
			System.out.println(item);
		}
	}
}